"""

"""
from functions import getHtml
from time import sleep
import requests
import re


def build_url():
    urlList = []
    x = 683  # 起始 683 终止 573 距离 110
    while True:
        x -= 1
        url = f'http://old.pep.com.cn/czsw/jshzhx/tbjxzy/xshyshu/8xshp/201009/t20100908_887{x}.htm'
        # print(url)
        urlList.append(url)
        if x == 573:
            break
    print('共有：', len(urlList), '页')
    return urlList


def write_photo():
    return


def get_photo(photo_url):

    return


def josn_purl(page):
    photoUrl = re.findall('<IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" src=".(.*?)" ', page)
    if len(photoUrl) == 0: photoUrl = re.findall('<IMG .*? src=".(.*?)"', page)
    if len(photoUrl) == 0: photoUrl = re.findall('<img .*? src=".(.*)" ', page)
    if len(photoUrl) == 0: photoUrl = re.findall('border="0" hspace="0" oldsrc="(.*?)">', page)
    return photoUrl


# 循环
def get_pageUrl(url_list):
    try:
        for url in url_list:
            photoUrl = josn_purl(getHtml(url))
            # nextUrl = re.findall('<A id=NextElementLink href=".././(.*?)"><DIV class=con_pagedown><STRONG>下一页</STRONG></DIV></A>', page)
            print(url, '\t', photoUrl)
            sleep(1)
    except IOError:
        pass
    return 0


def main(url):
    """

    :param url:
    :return:
    """
    get_pageUrl(url)
    return 0


if __name__ == '__main__':
    coverURL = 'http://old.pep.com.cn/czsw/jshzhx/tbjxzy/xshyshu/8xshp/201009/t20100908_887682.htm'
    main(build_url())
